<template>
	<view class="container" v-if="list">
		<view v-for="(item, index) in filteredList" :key="index" class="list-item"
			@touchstart.stop="handleTouchStart($event, index)" @touchmove.stop="handleTouchMove($event, index)"
			@touchend.stop="handleTouchEnd(index)" :style="{ transform: `translateX(${item.offsetX}rpx)` }">
			<view class="content">
				<text class="title">{{ item.productName }}</text>
				<text class="subtitle" v-if="item.sku" style="margin-right:60rpx;"> {{ item.sku + '*' + item.payNum}}
				</text>
				<text class="subtitle" v-else style="margin-right:60rpx;color: crimson;">
					请选择尺码
				</text>
				<text class="subtitle">￥{{ item.price }}</text>
			</view>
			<view class="action-btns">
				<view class="replacement bnt cancelBnt" @tap="sizeChange(item,index)" style="background-color: #ED7B2F; color: #fff;">修改数量</view>
				<view class="replacement bnt cancelBnt " style="background-color: red; color: #fff;" @tap="handleDelete(index)">删除</view>
			</view>
		</view>
		<view class="btn_box">
			<!-- <view class=" bnt cancelBnt" @tap="addPruduct">
				添加商品
			</view> -->
			<view class="bnt cancelBnt" @tap="confirmAdjustment">
				确认调整
			</view>
		</view>
		<uni-popup @maskClick="maskClick" ref="popup" type="center" background-color="#fff"
			border-radius="10px 10px 0 0">
			<view class="product-window"
				:class="(attr.cartAttr === true ? 'on' : '') + ' ' + (iSbnt?'join':'') + ' ' + (iScart?'joinCart':'')">
				<view class="textpic acea-row row-between-wrapper">
					<view class="pictrue" @click="showImg()">
						<image :src="attr.productSelect.image"></image>
					</view>
					<view class="text">
						<view class="line1">
							{{ attr.productSelect.name }}
						</view>
						<view class="money">
							<view class="mt-12">
								<text class="stock">
									库存:{{ attr.productSelect.groupPrice&&attr.productSelect.stock>0?attr.productSelect.groupStock:attr.productSelect.stock }}</text>
							</view>
						</view>
					</view>
					<view class="iconfont icon-guanbi" @click="closeAttr"></view>
				</view>
				<view class="rollTop">
					<view class="productWinList">
						<view class="item" v-for="(item, indexw) in attr.productAttr" :key="indexw">
							<view class="title">{{ item.attrName }}</view>
							<view class="listn acea-row row-middle">
								<view class="itemn flex"
									:class="item.index === itemn.optionName&&(marketingType === 0||productType===1)?'groupOn':item.index === itemn.optionName?'on':''"
									v-for="(itemn, indexn) in item.optionList"
									@click="onlyReduceOnSizeChange && sizeChangeIndex !== '' && attr.productSelect.max_num !== undefined ? null : tapAttr(indexw, indexn,item)"
									:key="indexn"
									:style="onlyReduceOnSizeChange && sizeChangeIndex !== '' && attr.productSelect.max_num !== undefined ? 'pointer-events: none; opacity: 0.5;' : ''">
									<image v-if="itemn.image" class="attr-img" :src="itemn.image" alt="" srcset="" />
									<text class="option-name">{{ itemn.optionName }}</text>
								</view>
							</view>
						</view>
					</view>
					<view class="cart acea-row row-between-wrapper">
						<view class="title">数量</view>
						<view class="carnum acea-row row-left">
							<view v-if="!isProductType" class="item reduce"
								:class="attr.productSelect.cart_num <= 1 ? 'on' : ''" @click="CartNumDes">
								-
							</view>
							<view class='item num'>
								<input type="number" :always-embed="true" :adjust-position="true" cursor-spacing="50"
									:disabled="isProductType"
									v-model="attr.productSelect.cart_num"
									:data-name="'productSelect.cart_num'"
									:min="1"
									:max="onlyReduceOnSizeChange && sizeChangeIndex !== '' && attr.productSelect.max_num !== undefined ? attr.productSelect.max_num : attr.productSelect.stock"
									@input="bindCode" maxlength="3">
							</view>
							<view class="item plus"
								:class="attr.productSelect.cart_num >= (onlyReduceOnSizeChange && sizeChangeIndex !== '' && attr.productSelect.max_num !== undefined ? attr.productSelect.max_num : attr.productSelect.stock) ? 'on': ''"
								@click="CartNumAdd(1)">
								+
							</view>
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		getOrderDetail,
		getProductDetail,
		personnelAdjustOrder
	} from '@/api/index.js'
	export default {
		data() {
			return {
				list: [],
				startX: 0, // 触摸起始X坐标
				currentIndex: -1, // 当前操作的索引
				deleteWidth: 200, // 新增删除按钮宽度定义（单位：rpx）
				orderNo: '',
				orderInfo: {},
				attr: {
					productSelect: {},
					cartAttr: true
				},
				productValue: {},
				isShowPopup: false,
				attrIndex: -1, // 当前操作的索引
				addList: [],
				sizeChangeIndex: '',
				onlyReduceOnSizeChange: true, // 新增开关，默认只能减少数量
			}
		},
		props: {
			iSbnt: {
				type: Number,
				default: 0
			},
			iSplus: {
				type: Number,
				default: 0
			},
			iScart: {
				type: Number,
				default: 0
			},
			// 商品类型 0=普通商品,1-积分商品,2-虚拟商品,4=视频号,5-云盘商品,6-卡密商品
			productType: {
				type: Number,
				default: 0
			},
			marketingType: {
				type: Number,
				default: 0
			},
		},
		computed: {
			isProductType() {
				return false;
			},
			// 过滤掉已删除的商品，避免v-for和v-if混用
			filteredList() {
				return this.list.filter(item => !item.isDelete);
			}
		},
		onLoad: function(options) {
			if (!options.orderNo) return uni.showToast({
				title: '缺少参数',
				icon: 'none'
			})
			this.$set(this, 'orderNo', options.orderNo);
			this.getOrderInfo()
			uni.$on('addProduct', this.addProductEmit)
		},
		methods: {
			arrayEquals(array1, array2) {
				// 先检查是否存在
				if (!(array1 || array1)) {
					return false;
				}
				// 先比较长度 
				if (array1.length != array2.length) {
					return false;
				}

				for (let i = 0, l = array1.length; i < l; i++) {
					// 检查是否为内嵌数组
					if (array1[i] instanceof Array && array2[i] instanceof Array) {
						// 递归比较数组
						if (!this.arrayEquals(array1[i], array2[i])) return false;
					} else if (array1[i] != array2[i]) { //标量比较 
						return false;
					}
				}
				return true;
			},

			bindCode(e) {
				let val = Number(e.detail.value);
				if (this.onlyReduceOnSizeChange && this.sizeChangeIndex !== '' && this.attr.productSelect.max_num !== undefined) {
					if (val > this.attr.productSelect.max_num) {
						this.$set(this.attr.productSelect, 'cart_num', this.attr.productSelect.max_num);
						return;
					}
				}
				if (val < 1) {
					this.$set(this.attr.productSelect, 'cart_num', 1);
					return;
				}
				this.$set(this.attr.productSelect, 'cart_num', val);
			},
			confirmAdjustment() {
				// 获取需要添加的商品列表
				let addList = this.list.reduce((acc, item) => {
					if (item.addList && !item.isDelete) {
						acc.push({
							number: item.addList.number,
							shopSpecId: item.addList.shopSpecId
						});
					}
					return acc;
				}, []);
				
				// 获取需要删除的商品列表
				let removeList = this.list.reduce((acc, item) => {
					// 如果是被删除的商品，或者更换了尺码的商品
					// 新增商品没 image 属性
					if ('addList' in item && 'image' in item || item.isDelete) {
						acc.push({
							number: item.oldPayNum,
							shopSpecId: item.attrValueId
						});
					}
					return acc;
				}, []);
				
				// 检查是否有变更
				if (addList.length === 0 && removeList.length === 0) {
					return uni.showToast({
						icon: 'none',
						title: '请先进行商品调整'
					});
				}
				personnelAdjustOrder({
					addList,
					removeList,
					orderNo: this.orderNo
				}).then(res => {
					if (res.data) {
						uni.showToast({
							icon: 'success',
							title: '调整成功'
						});
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/orderManageRider/orderManageRider'
							});
						}, 1500);
					}
				}).catch(e => {
					uni.showToast({
						icon: 'error',
						title: e || '系统异常'
					});
				});
			},
			maskClick() {
				// 检查是否选择了所有尺码
				const hasUnselectedSize = this.attr.productAttr.some(attr => !attr.index);
				if (hasUnselectedSize) {
					uni.showToast({
						title: '请选择尺码',
						icon: 'none'
					});
					return;
				}
				
				// 检查数量是否有效
				if (!this.attr.productSelect.cart_num || this.attr.productSelect.cart_num < 1) {
					uni.showToast({
						title: '请选择数量',
						icon: 'none'
					});
					return;
				}
				
				// 检查库存是否足够
				if (this.attr.productSelect.cart_num > this.attr.productSelect.stock) {
					uni.showToast({
						title: '库存不足',
						icon: 'none'
					});
					return;
				}
				
				this.list.forEach((item, index) => {
					if (
						item.productId == this.attr.productSelect.productId && this.sizeChangeIndex == index
					) {
						this.$set(item, 'addList', {
							number: this.attr.productSelect.cart_num,
							shopSpecId: this.attr.productSelect.id,
						})
						this.$set(item, 'payNum', this.attr.productSelect.cart_num)
						this.$set(item, 'sku', this.attr.productSelect.sku)
					}
				})
			},
			addProductEmit(item) {
				// this.addList.push(item)
				if (this.list.find(item => item.productId == item.id)) return
				this.list.push({
					productName: item.name,
					price: item.price,
					productId: item.id,
					offsetX: 0,
					attrValueId: item.attrValueId
				})
			},
			addPruduct() {
				uni.navigateTo({
					url: '/pages/productManage/productManage?type=' + 'add' + '&orderNo=' + this.orderNo
				})
			},
			CartNumDes(number) {
				if (this.attr.productSelect.cart_num == 1) return
				this.$set(this.attr.productSelect, "cart_num", this.attr.productSelect.cart_num - 1);
			},
			CartNumAdd(number) {
				if (this.onlyReduceOnSizeChange && this.sizeChangeIndex !== '' && this.attr.productSelect.max_num !== undefined) {
					// 只能减少，不能增加
					if (this.attr.productSelect.cart_num >= this.attr.productSelect.max_num) {
						uni.showToast({
							title: '只能减少数量',
							icon: 'none'
						});
						return;
					}
				}
				if (!this.attr.productSelect || !this.attr.productSelect.stock) return;
				if (this.attr.productSelect.cart_num >= this.attr.productSelect.stock) {
					uni.showToast({
						title: '已达到最大库存',
						icon: 'none'
					});
					return;
				}
				this.$set(this.attr.productSelect, "cart_num", this.attr.productSelect.cart_num + 1);
			},
			tapAttr: function(indexw, indexn, item) {
				if (this.onlyReduceOnSizeChange && this.sizeChangeIndex !== '' && this.attr.productSelect.max_num !== undefined) {
					// 禁止切换规格
					return;
				}
				let that = this;
				that.$emit("attrVal", {
					indexw: indexw,
					indexn: indexn
				});
				this.$set(this.attr.productAttr[indexw], 'index', item.optionList[indexn].optionName);
				const currentCartNum = this.attr.productSelect.cart_num || 1;
				const newProductValue = this.productValue[this.attr.productAttr.map(item => item.index).toString()];
				const newCartNum = newProductValue.stock === 0 ? 0 : (currentCartNum > newProductValue.stock ? newProductValue.stock : currentCartNum);
				this.$set(this.attr, "productSelect", {
					...newProductValue,
					cart_num: newCartNum
				});
			},

			sizeChange(item, indexs) {
				this.sizeChangeIndex = indexs
				getProductDetail(item.productId).then(res => {
					this.attrIndex = indexs
					let data = res.data;
					this.$set(this.attr, "productAttr", data.productAttr);
					this.$set(this, "productValue", data.productValue);
					if (item.sku) {
						const currentSku = item.sku.split(',');
						this.attr.productAttr.forEach((attrItem, index) => {
							this.$set(attrItem, "index", currentSku[index]);
						});
						const selectedSku = this.attr.productAttr.map(item => item.index).toString();
						const selectedProduct = data.productValue[selectedSku];
						if (selectedProduct) {
							this.$set(this.attr, "productSelect", {
								...selectedProduct,
								cart_num: item.payNum || 1,
								max_num: item.payNum || 1 // 记录原数量为最大值
							});
						}
					} else {
						this.attr.productAttr.forEach((attrItem, index) => {
							if (index === 0 && attrItem.optionList.length > 0) {
								this.$set(attrItem, "index", attrItem.optionList[0].optionName);
							}
						});
						const selectedSku = this.attr.productAttr.map(item => item.index).toString();
						const selectedProduct = data.productValue[selectedSku];
						if (selectedProduct) {
							this.$set(this.attr, "productSelect", {
								...selectedProduct,
								cart_num: 1,
								max_num: 1
							});
						}
					}
					this.$refs.popup.open()
				})
			},
			getOrderInfo: function() {
				let that = this;
				uni.showLoading({
					title: "正在加载中"
				});
				getOrderDetail(that.orderNo).then(res => {
					uni.hideLoading();
					let data = res.data;
					that.$set(that, 'orderInfo', data);
					that.list = res.data.merchantOrderList[0].orderInfoList
					that.list.forEach((item, index) => {
						// item.offsetX = 0
						this.$set(item, 'oldPayNum', item.payNum)
						this.$set(item, 'offsetX', 0)
						this.$set(item, 'isDelete', false)
					})
					that.list = list
					console.log(that.list, 55);
				}).catch(err => {
					console.log(err);
				});
			},
			handleTouchStart(e, index) {
				this.startX = e.touches[0].pageX
				this.currentIndex = index
				console.log(64);
				// 重置其他项的偏移
				this.list.forEach((item, i) => {
					if (i !== index) item.offsetX = 0
				})
			},

			handleTouchMove(e, index) {
				if (index !== this.currentIndex) return
				const currentX = e.touches[0].pageX
				const diffX = currentX - this.startX
				const currentOffset = this.list[index].offsetX
				let newOffset = currentOffset + diffX * 0.6 // 带阻尼系数

				// 使用已定义的deleteWidth限制范围
				newOffset = Math.min(0, Math.max(newOffset, -this.deleteWidth))

				this.list[index].offsetX = newOffset

				this.startX = currentX
			},

			handleTouchEnd(index) {
				const offsetX = this.list[index].offsetX
				const threshold = this.deleteWidth * 0.4
				// 自动吸附逻辑
				if (offsetX < -threshold) {
					this.list[index].offsetX = -this.deleteWidth
					console.log(this.list);
				} else {
					this.list[index].offsetX = 0
				}
			},

			handleDelete(index) {
				const notDeletedCount = this.list.filter(item => !item.isDelete).length;
				if (notDeletedCount <= 1) {
					uni.showToast({
						title: '至少保留一项，不能全部删除',
						icon: 'none'
					});
					return;
				}
				uni.showModal({
					title: '确认删除',
					content: '确定要删除该项吗？',
					success: res => {
						if (res.confirm) {
							if (this.list[index].hasOwnProperty('isDelete')) {
								this.$set(this.list, index, Object.assign(this.list[index], {
									isDelete: true
								}))
							} else {
								// this.list.splice(index, 1)
							}
						}
					}
				})
			}
		},

	}
</script>

<style lang="scss" scoped>
	/* 基础样式 */
	.container {
		padding: 20rpx;
		background: #f5f5f5;
		height: 100vh;
		background: #F5F5F5;
		box-sizing: border-box;
		overflow: hidden;
	}

	.list-item {
		position: relative;
		height: 160rpx;
		margin-bottom: 20rpx;
		background: #fff;
		border-radius: 12rpx;
		transition: transform 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
		/* 允许删除按钮显示 */

		.content {
			padding: 24rpx;

			.title {
				font-size: 30rpx;
				color: #333;
				display: block;
				margin-bottom: 12rpx;
			}

			.subtitle {
				font-size: 24rpx;
				color: #666;
			}
		}

		.action-btns {
			display: flex;
			flex-direction: row;
			align-items: center;
			gap: 20rpx;
			position: absolute;
			right: 30rpx;
			top: 50%;
			transform: translateY(-50%);
			z-index: 2;
		}

		.replacement {
			border-radius: 20rpx;
			padding: 6rpx 30rpx;
		}

		.delete-btn {
			position: absolute;
			top: 0;
			bottom: 0;
			width: 160rpx;
			background: #e64340;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			z-index: 2;
			/* 确保按钮在顶层 */
		}
	}

	.attr-img {
		width: 37rpx;
		height: 37rpx;
		margin-right: 12rpx;
		border-radius: 8rpx;
	}

	.product-window {
		position: fixed;
		bottom: 0;
		width: 100%;
		left: 0;
		background-color: #fff;
		z-index: 77;
		border-radius: 16rpx 16rpx 0 0;
		padding-bottom: 100rpx;
		padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);
		transform: translate3d(0, 100%, 0);
		transition: all .2s cubic-bezier(0, 0, .25, 1);
	}

	.product-window.on {
		transform: translate3d(0, 0, 0);
	}

	.product-window.join {
		padding-bottom: 30rpx;
	}

	.product-window.joinCart {
		padding-bottom: 30rpx;
		z-index: 999;
	}

	.product-window .textpic {
		padding: 0 130rpx 0 24rpx;
		margin-top: 29rpx;
		position: relative;
	}

	.product-window .textpic .pictrue {
		width: 150rpx;
		height: 150rpx;
	}

	.product-window .textpic .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 10rpx;
	}

	.product-window .textpic .text {
		width: 424rpx;
		font-size: 28rpx;
		color: #333333;
	}

	.product-window .textpic .text .money {
		font-size: 28rpx;
		margin-top: 12rpx;
		// @include price_color(theme);
	}

	.product-window .textpic .text .money .num {
		font-family: PingFang SC;
		font-size: 36rpx;
		font-weight: 600;
	}

	.product-window .textpic .text .money .stock {
		color: #999;
	}

	.product-window .textpic .iconfont {
		position: absolute;
		right: 30rpx;
		top: -5rpx;
		font-size: 35rpx;
		color: #8a8a8a;
	}

	.product-window .rollTop {
		max-height: 760rpx; //规格较多时候弹框高度为高为800rpx
		overflow: auto;
		margin-top: 36rpx;
	}

	.product-window .productWinList .item~.item {
		margin-top: 36rpx;
	}

	.product-window .productWinList .item .title {
		font-size: 28rpx;
		color: #999;
		padding: 0 30rpx;
	}

	.product-window .productWinList .item .listn {
		padding: 0 30rpx 0 16rpx;
	}

	.product-window .productWinList .item .listn .itemn {
		border: 1px solid #F2F2F2;
		font-size: 26rpx;
		color: #282828;
		padding: 4rpx 0;
		border-radius: 8rpx;
		margin: 20rpx 0 0 14rpx;
		background-color: #F2F2F2;

		.attr-img {
			margin: 0 -8rpx 0 4rpx;
		}

		.option-name {
			margin: 0 20rpx 0;
		}
	}

	.product-window .productWinList .item .listn .itemn.on {
		// @include main_color(theme);
		// @include coupons_border_color(theme);
		// @include cate-two-btn(theme);
	}

	.product-window .productWinList .item .listn .itemn.limit {
		color: #999;
		text-decoration: line-through;
	}

	.product-window .cart {
		margin-top: 50rpx;
		margin-bottom: 30rpx;
		padding: 0 24rpx;
	}

	.product-window .cart .title {
		font-size: 30rpx;
		color: #999;
	}

	.product-window .cart .carnum {
		height: 54rpx;
	}

	.product-window .cart .carnum view {
		// border: 1px solid #a4a4a4;
		width: 84rpx;
		text-align: center;
		height: 100%;
		line-height: 54rpx;
		color: #282828;
		font-size: 45rpx;
	}

	.product-window .cart .carnum .reduce {
		border-right: 0;
		border-radius: 6rpx 0 0 6rpx;
		line-height: 48rpx;
	}

	.product-window .cart .carnum .reduce.on {
		// border-color: #e3e3e3;
		color: #DEDEDE;
		font-size: 44rpx;
	}

	.product-window .cart .carnum .plus {
		border-left: 0;
		border-radius: 0 6rpx 6rpx 0;
		line-height: 46rpx;
	}

	.product-window .cart .carnum .plus.on {
		border-color: #e3e3e3;
		color: #dedede;
	}

	.product-window .cart .carnum .num {
		background: rgba(242, 242, 242, 1);
		color: #282828;
		font-size: 28rpx;
		border-radius: 12rpx;
		line-height: 54rpx;
		height: 54rpx;

		input {
			display: -webkit-inline-box;
			line-height: 54rpx;
			height: 54rpx;
		}
	}

	.product-window .joinBnt {
		font-size: 30rpx;
		width: 620rpx;
		height: 86rpx;
		border-radius: 50rpx;
		text-align: center;
		line-height: 86rpx;
		color: #fff;
		margin: 21rpx auto 0 auto;
	}

	.align-baseline {
		align-items: baseline;
	}

	.bg_color {
		// @include main-bg_color(theme);
	}

	.product-window .joinBnt.on {
		background-color: #bbb;
		color: #fff;
	}

	.align-center {
		align-items: center;
	}

	.vip_icon {
		width: 44rpx;
		height: 28rpx;
	}

	.vip_money {
		background: #FFE7B9;
		border-radius: 4px;
		font-size: 22rpx;
		color: #333;
		line-height: 28rpx;
		text-align: center;
		padding: 0 6rpx;
		box-sizing: border-box;
		margin-left: -4rpx;
	}

	.pl-2 {
		padding-left: 20rpx;
	}

	.limit-buy {
		font-weight: 400;
		font-size: 22rpx;
		color: #1DB0FC;
		margin-left: 25%;
	}

	.groupOn {
		background: #EAF7FF !important;
		border: 1px solid #1DB0FC !important;
		color: #1DB0FC !important;
	}

	.btn_box {
		display: flex;
		position: absolute;
		bottom: 200rpx;
		left: 50%;
		transform: translateX(-50%);

		.bnt {
			border: 1rpx solid #1296db;
			color: #fff;
			background: #1296db;
			padding: 6rpx 30rpx;
			border-radius: 50rpx;
			margin: 0 60rpx;
		}
	}

	/* 手机端适配 (小于768px) */
	@media screen and (max-width: 768px) {
		.container {
			padding: 15rpx;
		}

		.list-item {
			height: 140rpx;
			margin-bottom: 15rpx;

			.content {
				padding: 20rpx;

				.title {
					font-size: 28rpx;
					margin-bottom: 10rpx;
				}

				.subtitle {
					font-size: 22rpx;
				}
			}

			.action-btns {
				gap: 12rpx;
				right: 16rpx;
			}

			.replacement {
				padding: 4rpx 16rpx;
				font-size: 24rpx;
			}

			.delete-btn {
				width: 120rpx;
				font-size: 24rpx;
			}
		}

		.btn_box {
			bottom: 150rpx;
			flex-direction: column;
			gap: 20rpx;

			.bnt {
				margin: 0;
				padding: 8rpx 40rpx;
				font-size: 28rpx;
			}
		}

		.product-window {
			.textpic {
				padding: 0 100rpx 0 20rpx;
				margin-top: 20rpx;

				.pictrue {
					width: 120rpx;
					height: 120rpx;
				}

				.text {
					width: 300rpx;
					font-size: 26rpx;
				}
			}

			.rollTop {
				max-height: 600rpx;
			}

			.productWinList .item .listn .itemn {
				font-size: 24rpx;
				padding: 6rpx 12rpx;
				margin: 15rpx 0 0 10rpx;
			}

			.cart .carnum view {
				width: 70rpx;
				font-size: 40rpx;
			}

			.cart .carnum .num {
				font-size: 26rpx;
			}
		}
	}

	/* iPad端适配 (768px - 1024px) */
	@media screen and (min-width: 769px) and (max-width: 1024px) {
		.container {
			padding: 30rpx;
			max-width: 960rpx;
			margin: 0 auto;
		}

		.list-item {
			height: 180rpx;
			margin-bottom: 25rpx;

			.content {
				padding: 30rpx;

				.title {
					font-size: 32rpx;
					margin-bottom: 15rpx;
				}

				.subtitle {
					font-size: 26rpx;
				}
			}

			.action-btns {
				gap: 16rpx;
				right: 24rpx;
			}

			.replacement {
				padding: 6rpx 22rpx;
				font-size: 26rpx;
			}

			.delete-btn {
				width: 180rpx;
				font-size: 30rpx;
			}
		}

		.btn_box {
			bottom: 250rpx;

			.bnt {
				padding: 10rpx 50rpx;
				font-size: 32rpx;
				margin: 0 80rpx;
			}
		}

		.product-window {
			max-width: 800rpx;
			left: 50%;
			transform: translateX(-50%) translate3d(0, 100%, 0);

			&.on {
				transform: translateX(-50%) translate3d(0, 0, 0);
			}

			.textpic {
				padding: 0 150rpx 0 30rpx;
				margin-top: 35rpx;

				.pictrue {
					width: 180rpx;
					height: 180rpx;
				}

				.text {
					width: 500rpx;
					font-size: 30rpx;
				}
			}

			.rollTop {
				max-height: 800rpx;
			}

			.productWinList .item .listn .itemn {
				font-size: 28rpx;
				padding: 8rpx 16rpx;
				margin: 25rpx 0 0 20rpx;
			}

			.cart .carnum view {
				width: 100rpx;
				font-size: 50rpx;
			}

			.cart .carnum .num {
				font-size: 30rpx;
			}
		}
	}

	/* 大屏设备适配 (大于1024px) */
	@media screen and (min-width: 1025px) {
		.container {
			padding: 40rpx;
			max-width: 1200rpx;
			margin: 0 auto;
		}

		.list-item {
			height: 200rpx;
			margin-bottom: 30rpx;

			.content {
				padding: 35rpx;

				.title {
					font-size: 36rpx;
					margin-bottom: 18rpx;
				}

				.subtitle {
					font-size: 28rpx;
				}
			}

			.action-btns {
				gap: 20rpx;
				right: 250rpx;
			}

			.replacement {
				padding: 10rpx 40rpx;
				font-size: 28rpx;
			}

			.delete-btn {
				width: 200rpx;
				font-size: 32rpx;
			}
		}

		.btn_box {
			bottom: 300rpx;

			.bnt {
				padding: 12rpx 60rpx;
				font-size: 36rpx;
				margin: 0 100rpx;
			}
		}

		.product-window {
			max-width: 900rpx;
			left: 50%;
			transform: translateX(-50%) translate3d(0, 100%, 0);

			&.on {
				transform: translateX(-50%) translate3d(0, 0, 0);
			}

			.textpic {
				padding: 0 180rpx 0 40rpx;
				margin-top: 40rpx;

				.pictrue {
					width: 200rpx;
					height: 200rpx;
				}

				.text {
					width: 600rpx;
					font-size: 32rpx;
				}
			}

			.rollTop {
				max-height: 900rpx;
			}

			.productWinList .item .listn .itemn {
				font-size: 30rpx;
				padding: 10rpx 20rpx;
				margin: 30rpx 0 0 25rpx;
			}

			.cart .carnum view {
				width: 120rpx;
				font-size: 55rpx;
			}

			.cart .carnum .num {
				font-size: 32rpx;
			}
		}
	}

	/* 横屏模式适配 */
	@media screen and (orientation: landscape) and (max-height: 600px) {
		.container {
			height: 100vh;
			padding: 15rpx;
		}

		.list-item {
			height: 120rpx;
			margin-bottom: 10rpx;

			.content {
				padding: 15rpx;

				.title {
					font-size: 26rpx;
					margin-bottom: 8rpx;
				}

				.subtitle {
					font-size: 20rpx;
				}
			}
		}

		.btn_box {
			bottom: 100rpx;
			flex-direction: row;
			gap: 30rpx;

			.bnt {
				padding: 6rpx 25rpx;
				font-size: 24rpx;
			}
		}

		.product-window {
			.rollTop {
				max-height: 400rpx;
			}
		}
	}

	/* 深色模式适配 */
	@media (prefers-color-scheme: dark) {
		.container {
			background: #1a1a1a;
		}

		.list-item {
			background: #2a2a2a;

			.content {
				.title {
					color: #e0e0e0;
				}

				.subtitle {
					color: #b0b0b0;
				}
			}
		}

		.product-window {
			background-color: #2a2a2a;

			.textpic .text {
				color: #e0e0e0;
			}

			.productWinList .item .title {
				color: #b0b0b0;
			}

			.productWinList .item .listn .itemn {
				background-color: #3a3a3a;
				border-color: #4a4a4a;
				color: #e0e0e0;
			}

			.cart .title {
				color: #b0b0b0;
			}

			.cart .carnum .num {
				background: #3a3a3a;
				color: #e0e0e0;
			}
		}
	}

	/* 高对比度模式适配 */
	@media (prefers-contrast: high) {
		.list-item {
			border: 2rpx solid #000;

			.replacement {
				border: 2rpx solid #1296db;
			}

			.delete-btn {
				border: 2rpx solid #e64340;
			}
		}

		.product-window .productWinList .item .listn .itemn {
			border: 2rpx solid #000;
		}
	}

	/* 减少动画模式适配 */
	@media (prefers-reduced-motion: reduce) {
		.list-item {
			transition: none;
		}

		.product-window {
			transition: none;
		}
	}
</style>